package com.gitee.ywj1352.proxy.dynamic.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by wenjie.yang on 3/25/2019.
 */
public class PersonProxy implements InvocationHandler{
  private Person person;


  public Object getInstance(Person person)throws Exception{
    this.person =person;
    Class<?> clazz = person.getClass();
    return Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), this);
  }


  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    System.out.println("i am jdk proxy,i get you");
    method.invoke(this.person,args);
    System.out.println("i am jdk proxy,bye");
    return proxy;
  }
}
